<template>
  <div>
    <el-dialog :title="title" :visible.sync="visible" width="800px" append-to-body custom-class="import-dialog">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="备注" prop="recordContent">
          <el-input v-model="form.recordContent" type="textarea" :rows="4" placeholder="请输入备注"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { debounce } from '@/utils'
import { receiveWorkOrder } from '@/api/houseManagement/workOrder'

export default {
  name: 'AcceptOrders',
  dicts:[],
  components: {
  },
  props: {
    title: {
      default: '接单'
    },
    value: {
      default: false
    },
    data: {
      default: undefined
    }
  },
  data() {
    return {
      form: {},
      rules: {
      },
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      //列表
      list: [],
    }
  },
  computed: {
    visible: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      }
    }
  },
  watch: {
    value: {
      handler(newVal, oldVal) {
        if (newVal) {
          this.init()
        }
      },
      immediate: true
    }
  },
  methods: {
    init() {
      this.reset()
    },
    reset() {
      this.form = {
        workOrderId: this.data.workOrderId, //工单编号
        recordContent: "" //记录内容
      }
      this.resetForm('form')
    },
    //提交表单
    submitForm: debounce(function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          receiveWorkOrder(this.form).then(response => {
            if (response.code == 200) {
              this.$emit('success')
              this.$message.success(response.msg||'操作成功')
              this.cancel()
              this.$emit('success')
            }
          })
        }
      })
    }, 500, false),
    cancel() {
      this.reset()
      this.visible = false
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/dialog";
</style>
